package top.atcra.rpc.transport.common;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;
import top.atcra.rpc.protection.health.ServiceHealthDetector;

public class ClientHeartbeatHandler  extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt)  {
        if (evt instanceof IdleStateEvent event) {
            // 写空闲
            if (event.state() == IdleStateEvent.WRITER_IDLE_STATE_EVENT.state()) {
                ServiceHealthDetector.sendHeartbeat(ctx.channel());
            }
        }
    }
}
